package com.zy.design.ext;

import com.zy.design.ext.service.EggLayAble;
import com.zy.design.ext.service.Flyable;
import com.zy.design.ext.service.imp.EggLayAbility;
import com.zy.design.ext.service.imp.FlyAbility;

/**
 * @author zhaoyi
 * @date 2021/2/5 11:42
 * 麻雀会下蛋 会飞
 * 当继承关系非常复杂时使用 接口 委托 组合 方式 更加清晰
 * 但是当继承结构简单不易变化时 继承更简洁
 * 这个例子其实相当结构少
 */
public class Sparrow implements EggLayAble, Flyable {

    //组合
    private EggLayAbility eggLayAbility = new EggLayAbility();
    private FlyAbility flyAbility = new FlyAbility();

    @Override
    public void layEgg() {
        //委托
        eggLayAbility.layEgg();
    }

    @Override
    public void fly() {
        //委托
        flyAbility.fly();
    }
}
